Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable IO and UpdateTest types #15104

Merged
merged 6 commits into from
Mar 31, 2023
Merged

Conversation

dduugg
Copy link
Sponsor Member

@dduugg dduugg commented Mar 30, 2023

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Enables types in Library/Homebrew/extend/io.rb and Library/Homebrew/dev-cmd/update-test.rb

Note that this is a bit clumsy in one case, where we mark an lvar as untyped. This is because Utils.popen_read resists a straightforward sig (The return type is the return type of the block given to it, or a String otherwise. Sorbet allows multiple sigs in the Ruby core and std libraries in order to express this, but doesn't allow it otherwise.)

@@ -1,22 +1,24 @@
# typed: false
# typed: true
# frozen_string_literal: true

class IO
def readline_nonblock(sep = $INPUT_RECORD_SEPARATOR)
line = +""
buffer = +""
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be outside the rescued block, so that line is provably a String when line.empty? is invoked below.

raise e if line.empty?
line.freeze
rescue IO::WaitReadable, EOFError
raise if line.empty?
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IO::WaitReadable is not technically an Exception, so it can't be passed to raise, but we can avoid the issue using an empty re-raise instead (e is not needed otherwise)

@dduugg dduugg force-pushed the enable-io-types branch 3 times, most recently from bcfcb64 to fa0caaa Compare March 31, 2023 00:20
@dduugg dduugg changed the title Add Utils popen sigs, enable IO types Enable IO and UpdateTest types Mar 31, 2023
@apainintheneck
Copy link
Contributor

Note that this is a bit clumsy in one case, where we mark an lvar as untyped. This is because Utils.popen_read resists a straightforward sig (The return type is the return type of the block given to it, or a String otherwise. Sorbet allows multiple sigs in the Ruby core and std libraries in order to express this, but doesn't allow it otherwise.)

Very interesting!

end_commit = "HEAD"
cd HOMEBREW_REPOSITORY do
start_commit = if (commit = args.commit)
start_commit = if (commit = T.let(args.commit, T.nilable(String)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really necessary? I tested it locally and it didn't seem to care.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh, are some of these changes only needed for typed: strict @dduugg?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, this is a vestige of attempting to type the Utils.popen* methods. Would you like me to remove it in the next typing PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dduugg No, all good!

end_commit = "HEAD"
cd HOMEBREW_REPOSITORY do
start_commit = if (commit = args.commit)
start_commit = if (commit = T.let(args.commit, T.nilable(String)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh, are some of these changes only needed for typed: strict @dduugg?

@MikeMcQuaid MikeMcQuaid merged commit 0d17bbb into Homebrew:master Mar 31, 2023
24 checks passed
@MikeMcQuaid
Copy link
Member

Thanks again @dduugg! Happy to chat more post-merge.

@dduugg dduugg mentioned this pull request Mar 31, 2023
7 tasks
@dduugg dduugg deleted the enable-io-types branch March 31, 2023 15:46
@github-actions github-actions bot added the outdated PR was locked due to age label May 4, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants